<template>
	<view class="content">
		<!-- 轮播图 开始 -->
		<view class="header_container">
			<view class="header_container_top"></view>
			<uni-swiper-dot :info="info" :current="current" field="content" :mode="mode" :dotsStyles="dotsStyles">
				<swiper class="swiper-box" @change="change" circular="true" interval="5000" autoplay="true">
					<swiper-item v-for="(item ,index) in info" :key="index">
						<view class="swiper-item">
							<image :src="imgUrl+item.image" mode=""></image>
						</view>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		
		<!-- 轮播图 结束 -->
		<!-- 今日推荐 开始 -->
		<view class="referrer">
			<view class="today display align-items"><text></text>今日推荐</view>
			<view class="referrer_cont">
				<view class="referrer_cont_list" v-for="(item,index) in GoodsListInfo" :key="index" @click="goGoodsDetails(item.id)">
					<image :src="imgUrl+item.goods_image" mode=""></image>
					<view class="title ellipsis">{{item.goods_name}}</view>
					<view class="moy">¥{{item.price}}</view>
					<image v-if="item.free_switch==1" src="../../static/icon/lp.png" mode="" class="dw"></image>

					<image v-if="item.new_switch==1&&item.free_switch!=1" src="../../static/icon/new_shop.png" mode="" class="dw"></image>
				</view>
			</view>
		</view>
		<!-- 今日推荐 结束 -->
		<!-- 弹窗 -->
		<view class="popup" v-if="showPopup">
			<view class="popup_container">
				<view class="popup_top">
					<view class="popup_top_name letter-spacing">输入邀请码</view>
					<input type="text" class="letter-spacing auto" value="" placeholder="请输入邀请码" />
					<view class="popup_button letter-spacing">确定</view>
				</view>
				<image class="popup_close auto" @click="closePopup" src="../../static/icon/close.png" mode=""></image>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		uniBadge,
		uniSwiperDot
	} from '@dcloudio/uni-ui'

	export default {
		components: {
			uniBadge,
			uniSwiperDot,
		},
		data() {
			return {
				info: [], //轮播
				GoodsListInfo: [], //商品
				current: 0,
				mode: 'dot',
				dotsStyles: {
					backgroundColor: '#ffffff',
					selectedBackgroundColor: '#294D7C',
					border: "#ffffff",
					selectedBorder: "#294D7C"
				},
				showPopup: false,
				imgUrl: ''
			}
		},
		onLoad(options) {
			var qrCodeUrl = decodeURIComponent(options.scene)|| '0';
			if(qrCodeUrl){
				let params = qrCodeUrl.split('=');
				switch (params[0]) {
					case 'ucode':
						uni.setStorageSync('formopenid', params[1])
						if (uni.getStorageSync('openid')) {
							this.getSj()
						}
						break;
					case 'goods_id':
						uni.navigateTo({
							url: "./particulars/index?goods_id=" + params[1]
						})
						break;
				}
			}
			this.imgUrl = this.$imgUrl
			this.getBanana()
			this.GoodsList()
		},
		onPullDownRefresh() {
			// this.info = []
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.GoodsList(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
				this.getBanana()
			}, 1000)
		},
		methods: {
			// 分享者
			getSj() {
				let that = this
				var formopenidAgain = uni.getStorageSync('formopenidAgain')
				var formopenid = uni.getStorageSync('formopenid')
				var openid = uni.getStorageSync('openid')
				if (formopenid != formopenidAgain) {
					uni.setStorageSync('formopenidAgain', formopenid)
					// 传递分享者的opemid
					var data = {
						openid: uni.getStorageSync('openid'),
						ucode: formopenid
					}
					that.$myRequest.post(that.$api.bingCode.bingCode, data).then(res => {
						console.log(res)
						if (res.code == '200') {


						} else {
							console.log(res.msg)
							// uni.showToast({
							// 	title: res.msg,
							// 	icon: "none"
							// })
						}
					})
				}
			},
			// 获取轮播数据
			getBanana() {
				let that = this
				this.$myRequest.post(this.$api.default.IndexbananaUrl).then(res => {
					if (res.code == '200') {
						that.info = res.data.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			// 获取商品
			GoodsList(callback) {
				let that = this
				this.$myRequest.post(this.$api.default.IndexGoodsListUrl).then(res => {
					if (res.code == '200') {
						this.GoodsListInfo = res.data.data
						callback && callback()
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			// 商品跳转
			goGoodsDetails(id) {
				uni.navigateTo({
					url: "./particulars/index?goods_id=" + id
				})
			},
			change(e) {
				this.current = e.detail.current;
			},

			//关闭邀请码
			closePopup() {
				this.showPopup = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		// width: 690rpx;
		margin: 0 auto;
		.header_container{
			height:350rpx;
			width: 100%;
			position: relative;
			.header_container_top{
				height:200rpx;
				background-color: #7fb3b1;
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				margin: auto;
				border-radius: 0 0 40rpx 40rpx;
			}
			.swiper-box {
				width: 690rpx;
				height: 300rpx;
				display: block;
				margin: auto;
				margin-top: 35rpx;
				.swiper-item {
					width: 100%;
					height: 100%;
			
					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
			
			
		}

		.referrer {
			width: 690rpx;
			margin: auto;
			.today {
				padding-left: 7rpx;
				height: 90rpx;
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: 500;
				color: #4b968d;
				line-height: 90rpx;

				text {
					width: 5rpx;
					height: 28rpx;
					background: #4b968d;
					margin-right: 11rpx;
					margin-top: 5rpx;
				}
			}

			.referrer_cont {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.referrer_cont_list {
					width: 331rpx;
					border: 1px solid #EAEDF1;
					border-radius: 10px;
					position: relative;
					margin-bottom: 25rpx;

					image {
						width: 100%;
						height: 331rpx;
						border-radius: 10px 10px 0 0;
					}

					.title {
						padding: 15rpx 14rpx 0rpx 14rpx;
						margin-bottom: 15rpx;
						font-size: 26rpx;
						color: #333333;
					}

					.moy {
						padding: 0rpx 14rpx 20rpx 14rpx;
						font-size: 32rpx;
						color: #F21515;
					}

					.dw {
						width: 144rpx;
						height: 142rpx;
						position: absolute;
						left: 0;
						top: 0;
						border-radius: 10px;
					}
				}
			}
		}

		.popup_container {
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			width: 570rpx;
			height: 614rpx;

			.popup_top {
				width: 570rpx;
				height: 530rpx;
				background-image: url(../../static/icon/yqm.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				position: relative;

				.popup_top_name {
					font-size: 40rpx;
					text-align: center;
					color: #fff;
					position: absolute;
					top: 85rpx;
					left: 0;
					right: 0;
					margin: auto;
				}

				input {
					width: 430rpx;
					height: 66rpx;
					background: #F5F5F5;
					border-radius: 33rpx;
					color: #CCCCCC;
					font-size: 26rpx;
					padding-left: 40rpx;
					position: absolute;
					bottom: 170rpx;
					left: 0;
					right: 0;
					margin: auto;
				}

				.popup_button {
					width: 290rpx;
					height: 76rpx;
					background-image: url(../../static/icon/btn.png);
					background-repeat: no-repeat;
					background-size: 100% 100%;
					text-align: center;
					color: #fff;
					font-size: 30rpx;
					line-height: 70rpx;
					position: absolute;
					bottom: 45rpx;
					left: 0;
					right: 0;
					margin: auto;
				}
			}

			.popup_close {
				width: 44rpx;
				height: 44rpx;
				display: block;
				margin-top: 38rpx;
			}
		}
	}
</style>
